home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor2 / poly7.doc < prev    next >
Text File  |  1995-03-31  |  6KB  |  179 lines

  1. POLY, by Wayne Scott  [upgrade to POLY on Goodies Disk #1.  -jkh-] 
  2.  
  3. Here it is, my polynomial routines version 3.2 
  4.  
  5. Changes from version 3.1: 
  6.           - Faster PMUL 
  7.           - RT now works with complex cooeffients 
  8.           - various bug fixes 
  9.  
  10. These routines are in the public domain, but I ask that if you use any of them 
  11. in one of your programs you give me credit.  I am also not responsible for any 
  12. damage caused by these programs. 
  13.  
  14. This package include the following programs. 
  15.  
  16. TRIM     Strip leading zeros from polynomial object. 
  17. IRT      Invert root program. Given n roots it return a nth degree polynomial. 
  18. PDER     Derivative of a polynomial. 
  19. RDER     Derivative of a rational function. 
  20. PF       Partial Fractions.  (Handles multiple roots!) 
  21. FCTP     Factor polynomial 
  22. RT       Find roots of any polynomial 
  23. L2A      Convert a list to an array and back. 
  24. PADD     Add two polynomials 
  25. PMUL     Multiply two polynomials. 
  26. PDIV     Divide two polynomials. 
  27. EVPLY    Evaluate a polynomial at a point. 
  28. COEF     Given an equation return a polynomial list. 
  29.  
  30. These programs are for the HP-48sx.  I have a version of them that works 
  31. correctly on the HP-28.  Send me mail if you want it. 
  32.  
  33. I think people will find these very useful and work as I say, but if you find 
  34. any bugs please send me E-Mail.  Comments are also welcome. 
  35.  
  36. Some of these routines could be faster (PF, PMUL, ...) tell me if you know how 
  37. to speed them up. 
  38.  
  39. Wayne Scott             |  INTERNET:   wscott@en.ecn.purdue.edu 
  40. Electrical Engineering  |  BITNET:     wscott%ea.ecn.purdue.edu@purccvm 
  41. Purdue University       |  UUCP:      {purdue,pur-ee}!en.ecn.purdue.edu!wscott 
  42.  
  43.  
  44. These programs all work on polynomials in the following form: 
  45.  
  46. 3*X^3-7*X^2+5 is entered as  { 3 -7 0 5 } 
  47.  
  48.  
  49. Reasons why I use lists instead of arrays include: 
  50.  
  51.         * lists look better on the stack.  (multi-line) 
  52.         * The interactive stack can quickly put serveral items in a 
  53.           list. 
  54.         * Hitting EVAL will quickly return the elements on a list. 
  55.         * the '+' key will add a element to the end or beginning of a list 
  56.           or concatenate two lists 
  57.         * Internally the main program that needs to be fast (BAIRS) 
  58.           does 100% stack maniplations so speed of arrays vs. lists was 
  59.           not a major issue. 
  60.         * It would be easier for later releases to include symbolic 
  61.           polynomials. 
  62.  
  63. úÄÄÄÄÄÄ¿ 
  64. 3 FCTP 3 (FaCTor Polynomial) 
  65. àÄÄÄÄÄÄù 
  66. When it is passed the cooeficients of a polynomial in a list it returns the 
  67. factor of that polynomial.  Example: 
  68.   
  69. 1: { 1 -17.8 99.41 -261.218 352.611 -134.106 } 
  70. FCTP 
  71. 3: { 1 -4.2 2.1 } 
  72. 2: { 1 -3.3 6.2 } 
  73. 1: { 1 -10.3 } 
  74.  
  75. This tells us that X^5-17.8*X^4+99.41*X^3-261.218*X^2+352.611*X-134.106 
  76. factors to (X^2-4.2*X+2.1)*(X^2-3.3*X+6.2)*(X-10.3) 
  77.  
  78. úÄÄÄÄ¿ 
  79. 3 RT 3 (RooTs) 
  80. àÄÄÄÄù 
  81. If given a polynomial it return its roots.  Example: 
  82.  
  83. 1: { 1 -17.8 99.41 -261.218 352.611 -134.106 } 
  84. RT 
  85. 5: 3.61986841536 
  86. 4: .58013158464 
  87. 3: (1.65, 1.8648056199) 
  88. 2: (1.65, -1.8648056199) 
  89. 1: 10.3 
  90.  
  91. RT will work with complex cooeffients in the polynomial. 
  92.  
  93. These programs use the BAIRS program which performs Bairstow's method of 
  94. quadratic factors and QUD which does the quadratic equation. 
  95.  
  96. úÄÄÄÄÄÄ¿ 
  97. 3 TRIM 3is used to strip the leading zeros from a polynomial list. 
  98. àÄÄÄÄÄÄù 
  99. Example: { 0 0 3 0 7 } TRIM => { 3 0 7 } 
  100.  
  101. úÄÄÄÄÄÄ¿ 
  102. 3 RDER 3will give the DERivative of a Rational function.  Example: 
  103. àÄÄÄÄÄÄù 
  104.     d        x + 4                   -X^2 - 8*x + 31 
  105.     --   -------------  =   -------------------------------- 
  106.     dx   x^2 - 7*x + 3      x^4 - 14*x^3 + 55*x^2 - 42*x + 9 
  107.  
  108. 2: { 1 4 } 
  109. 1: { 1 -7 3 } 
  110. RDER 
  111. 2: { -1 -8 31 } 
  112. 1: { 1 -14 55 -42 9 } 
  113.  
  114. úÄÄÄÄÄ¿ 
  115. 3 IRT 3(Inverse RT) will return a polynomial whose roots you specify. 
  116. àÄÄÄÄÄù 
  117. Example:  If a transfer function has zeros at -1, 1 and 5 the function is 
  118.           x^3 - 5*x^2 - x + 5 
  119.  
  120. 1: { -1 1 5 } 
  121. IRT 
  122. 1: { 1 -5 -1 5 } 
  123.  
  124. úÄÄÄÄÄÄ¿ 
  125. 3 PDER 3will return the DERivative of a Polynomial.  Example: 
  126. àÄÄÄÄÄÄù 
  127.    The  d/dx (x^3 - 5*x^2 - x + 5) = 3*x^2 - 10*x - 1 
  128.  
  129. 1: { 1 -5 -1 5 } 
  130. PDER 
  131. 1: { 3 -10 -1 } 
  132.  
  133. úÄÄÄÄ¿ 
  134. 3 PF 3will do a Partial Fraction expansion on a transfer function. 
  135. àÄÄÄÄù 
  136. Example: 
  137.            s + 5         1/18    5/270     2/3       1/9     2/27 
  138.      ----------------- = ----- + ----- - ------- - ------- - ----- 
  139.      (s-4)(s+2)(s-1)^3   (s-4)   (s+2)   (s-1)^3   (s-1)^2   (s-1)  
  140.  
  141. 2: { 1 5 } 
  142. 1: { 4 -2 1 1 1 } 
  143. PF 
  144. 1: { 5.5555e-2 1.85185e-2 -.6666 -.11111 -.074074 } 
  145.  
  146. This program expects the polynomial of the numerator to be on level 2 and 
  147. a list with the poles to be on level 1.  Repeated poles are suported but 
  148. they must be listed in order.  The output is a list of the values of the  
  149. fraction in the same order as the poles were entered. 
  150.  
  151. úÄÄÄÄÄÄâÄÄÄÄÄÄâÄÄÄÄÄÄ¿ 
  152. 3 PADD 3 PMUL 3 PDIV 3are all obvious, they take two polynomial lists off 
  153. àÄÄÄÄÄÄáÄÄÄÄÄÄáÄÄÄÄÄÄù 
  154. the stack and perform the operation on them. 
  155.  
  156. PDIV returns the quotient polynomial and the remainder polynomial. 
  157.  
  158. úÄÄÄÄÄ¿ 
  159. 3 L2A 3converts a list to an array. (and back) 
  160. àÄÄÄÄÄù 
  161. 1: { 1 2 3 } 
  162. L2A 
  163. 1: [ 1 2 3 ] 
  164. L2A 
  165. 1: { 1 2 3 } 
  166.  
  167. úÄÄÄÄÄÄÄ¿ 
  168. 3 EVPLY 3evaluates any polynomial at a point. 
  169. àÄÄÄÄÄÄÄù 
  170. x^3 - 3*x^2 +10*x - 5 | x=2.5   = 16.875 
  171.  
  172. 2: { 1 -3 10 -5 } 
  173. 1: 2.5 
  174. EVPLY 
  175. 1: 16.875 
  176.  
  177. P.S. Many thanks to Mattias Dahl & Henrik Johansson for fixs they have 
  178.      made. 
  179.